# This class will store information about the current star system #

import random
import math
import starfield
from mathutils import Vector
from starfield import Star
from starfield import Planet
from starfield import NameGenerator
from starfield import Hash
import starfield



class Galaxy:
	def __init__(self):
		
		self.namer = NameGenerator.NameGenerator(random.randint(0, 1000), 2)
		self.namer.inputFile("star_names.txt")
			
		# nice to know what I am #
		self.role = "galaxy"
		
		self.stars = []
		self.stars_by_id = {}
		self.stars_by_name = {}
		
		
	def placePlayers(self, players):	
		#neutered for now
		chosen = []
		# find suitable stars #
		for i in range(players):
			chosen.append(random.choice(self.stars))
		
		# all done #
		return chosen
	
	def generateStars(self, seed, size):
		
		self.seed = seed
		self.size = size
		self.stars = []
		maxDist = starfield.STAR_MAX_DISTANCE
		hash = Hash.Hash(maxDist)
		random.seed(seed)
		
		
		while len(self.stars) < self.size:
			name = self.namer.getName()
			loc = Vector(  [(random.random()-.5) * maxDist*(self.size/10),
							(random.random()-.5) * maxDist*(self.size/10),
							(random.random()-.5) * maxDist*(self.size/10)  ])
			print(loc)
			neighbors = hash.neighbors(loc, starfield.STAR_MIN_DISTANCE)
			if len(neighbors) == 0:
				star = Star.Star(name, loc)
				star.rotation = random.choice([-1, 1])
				
				self.stars.append(star)
				self.stars_by_id[star.id] = star
				lastLoc = loc

	
		
		